#ifndef _LOGGER_H
#define _LOGGER_H

#include "log4cplus/logger.h" 
#include "log4cplus/fileappender.h" 
#include "log4cplus/consoleappender.h" 
#include "log4cplus/layout.h"
#include "log4cplus/loggingmacros.h"
#include "log4cplus/spi/loggingevent.h"
#include <string>

using std::string;
using namespace log4cplus; 
using namespace log4cplus::helpers; 

class MyLogger
{
public:
	MyLogger(const string& name,const string& pattern,const string& file,bool console);
	Logger& GetLogger(){return m_logger;}

	class My_ConsoleAppender : public ConsoleAppender
	{
		virtual void append(const spi::InternalLoggingEvent& event);
	private:
		My_CriticalSection m_setcolorCritical;
	};
private:
	string m_pttern;
	Logger m_logger;
	std::auto_ptr<Layout> m_layoutFile;
	std::auto_ptr<Layout> m_layoutConsole;

};
#if defined ROBOT
	#define 	LOG_DIR "Robot/"
#elif defined WORLDSERVER
	#define     LOG_DIR "WorldServer/"
#else	
	#define     LOG_DIR ""
#endif

extern void Initlogger();
extern void CleanUplogger();
extern MyLogger* g_netLog;
#define NET_WARN(format,...) LOG4CPLUS_WARN_FMT(g_netLog->GetLogger(),format,__VA_ARGS__)
#define NET_ERROR(format,...) LOG4CPLUS_ERROR_FMT(g_netLog->GetLogger(),format,__VA_ARGS__)
#define NET_LOG(format,...)// LOG4CPLUS_INFO_FMT(g_netLog->GetLogger(),format,__VA_ARGS__)


extern MyLogger* g_commonLog;
#define COMMON_WARN(format,...) LOG4CPLUS_WARN_FMT(g_commonLog->GetLogger(),format,__VA_ARGS__)
#define COMMON_ERROR(format,...) LOG4CPLUS_ERROR_FMT(g_commonLog->GetLogger(),format,__VA_ARGS__)
#define COMMON_LOG(format,...) LOG4CPLUS_INFO_FMT(g_commonLog->GetLogger(),format,__VA_ARGS__)
#define COMMON_DEBUG(format,...)// LOG4CPLUS_DEBUG_FMT(g_commonLog->GetLogger(),format,__VA_ARGS__)


#endif